/*******************************************************************************
 *                                    ZLG
 *                         ----------------------------
 *                         innovating embedded platform
 *
 * Copyright (c) 2001-present Guangzhou ZHIYUAN Electronics Co., Ltd.
 * All rights reserved.
 *
 * Contact information:
 * web site:    https://www.zlg.cn
 *******************************************************************************/
/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "core/include/hpm6e00_pcfg.h"

/*******************************************************************************
 * Code
 ******************************************************************************/
/**
 * \brief DCDC 电压设置
 *
 * \param[in] mv 要设置的电压值
 *
 * \retval 成功返回 0
 */
int pcfg_dcdc_voltage_set(uint16_t mv){
    uint32_t tmp;

    if ((mv < PCFG_SOC_DCDC_MIN_VOLTAGE_IN_MV) || (mv > PCFG_SOC_DCDC_MAX_VOLTAGE_IN_MV)) {
        return -EINVAL;
    }
    tmp  = READ_REG32(HPM_PCFG->DCDC_MODE) & (~(PCFG_DCDC_MODE_VOLT_MASK));
    tmp |= (mv << PCFG_DCDC_MODE_VOLT_POS);

    WRITE_REG32(HPM_PCFG->DCDC_MODE, tmp);

    return 0;
}
